//
//  FJLottieAnimationProtocol.swift
//  FruitJuice
//
//  Created by Rae on 2023/12/20.
//

import UIKit
import Lottie

struct AIGirlLottieAnimationWrapper<Base> {
    let base: Base
    init(_ base: Base) {
        self.base = base
    }
}

protocol AIGirlLottieAnimationProtocol { }
extension AIGirlLottieAnimationProtocol {
    ///
    public var lottieAnimation: AIGirlLottieAnimationWrapper<Self> {
        get { return AIGirlLottieAnimationWrapper(self) }
        set { }
    }
    
}

typealias AIGirlLottieAnimationView = LottieAnimationView

extension AIGirlLottieAnimationWrapper {
    
    func make(_ json: AIGirlJsonType, loopMode: LottieLoopMode = .loop, speed: CGFloat = 1.0) -> AIGirlLottieAnimationView {
        make(json, loopMode: loopMode, speed: speed, playFinishBlock: nil)
    }
    
    func make(_ name: AIGirlJsonType, loopMode: LottieLoopMode = .loop, speed: CGFloat = 1.0, contentMode: UIView.ContentMode = .scaleAspectFill, playFinishBlock: ((Bool) -> Void)? = nil) -> AIGirlLottieAnimationView {
        let view = AIGirlLottieAnimationView(name: name.rawValue, bundle: .main)
        view.contentMode = contentMode
        view.loopMode = loopMode
        view.shouldRasterizeWhenIdle = true
        view.backgroundBehavior = .pauseAndRestore
        view.currentProgress = 0
        view.animationSpeed = speed
        view.play(completion: playFinishBlock)
        return view
    }
    
}

extension AIGirlLottieAnimationWrapper {
    
    enum AIGirlJsonType: String {
        
        case loading = "AILoading"
        case msg_loading = "msgLoading"
        case subscribe = "subscribe"
        case info_loading = "infoLoading"
        
        case level_1 = "level1"
        case level_2 = "level2"
        case level_3 = "level3"
        case level_4 = "level4"
        case level_5 = "level5"
        case level_6 = "level6"
        case level_7 = "level7"
        case level_8 = "level8"
        case level_9 = "level9"
        case level_10 = "level10"
        
    }
    
}
